package GUILayer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
 
import javax.swing.JFormattedTextField.AbstractFormatter;
 
public class DateLabelFormatter extends AbstractFormatter {
	private static final long serialVersionUID = 1L;
	
	private SimpleDateFormat dateFormatter;
	
	public DateLabelFormatter(){
		this.dateFormatter = new SimpleDateFormat("dd.MM.yyyy");
	}
    
	public DateLabelFormatter(SimpleDateFormat dateFormatter){
		this.dateFormatter = dateFormatter;
	}
    
    
    @Override
    public Object stringToValue(String text) throws ParseException {
        return dateFormatter.parseObject(text);
    }
 
    @Override
    public String valueToString(Object value) throws ParseException {
        if (value != null) {
            Calendar cal = (Calendar) value;
            return dateFormatter.format(cal.getTime());
        }
         
        return "";
    }
 
}